﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
using System.Text;
namespace IHISCETeim.Web.MachineSys.FTradeModel
{
    public partial class FTradeInvoiceReUse : PageBase
    {
        protected override string DWZRef
        {
            get
            {
                return "FTradeReceivablesListEasyUI";
            }
        }

        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.应收帐款_发票 };
            }
        }


        protected int id
        {
            get
            {

                return GetRequestValue<int>("id", 0);
            }
        }
        private FTradeInvoiceInfo _obj = null;
        protected FTradeInvoiceInfo obj
        {
            get
            {
                if (_obj == null)
                {
                    _obj = FTradeInvoiceController.GetById(id);
                }
                return _obj;
            }
        }

        private FTradeReceivablesInfo _objft = null;
        protected FTradeReceivablesInfo objft
        {
            get
            {
                if (_objft == null)
                {
                    _objft = FTradeReceivablesController.GetByFTradeID(obj.FTradeID);
                }
                return _objft;
            }
        }

        protected DataTable GetOld()
        {
            int TotalCount = 0;
            DataTableCollection dts = FTradeReceivablesController.GetPagination(string.Format(" JiHao='{0}' and FTradeReceivables.FTradeID<>{1} and shuliang<>-1", objft.JiHao, obj.FTradeID), pageNum, numPerPage, " shuliang desc ", ref TotalCount);
            return dts[0];
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "reuse")
            {
                addmenu();
            }
            else
            {
                rpOld.DataSource = GetOld();
                rpOld.DataBind();
            }
        }
        private void addmenu()
        {
            int newFTradeID = GetRequestValue<int>("newFTradeID", 0);

            if (newFTradeID <= 0)
            {
                AlertJson("请选择转移后的合同");
                return;
            }

            bool msg = FTradeInvoiceController.ReUse(id, newFTradeID);

          
            if (msg)
                SuccessJson("转移成功", "FTradeInvoiceList");
            else
            {

                ErrorJson("转移失败");
            }
        }
    }
}